<template>
<div>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
  </el-breadcrumb> 
  <el-card class="box-card"  >

    <el-row :gutter="20">
      <el-col :span="8"> <el-input placeholder="请输入内容" v-model='orderId'>
        <el-button slot="append" icon="el-icon-search" @click='searchOrder(orderId)'></el-button>
      </el-input></el-col> 
    </el-row>
    <el-table
      :data="ordersList"
      style="width: 100%" border  stripe  class="table">
      <el-table-column  type="index"  label="#" width="49"  >

      </el-table-column>
      <el-table-column
        prop="orderId"
        label="订单编号">
      </el-table-column> 
      <el-table-column
        prop="commons"
        label="商品名">
      </el-table-column>

      <el-table-column  prop="uid"  label="购买者"></el-table-column>
      <el-table-column  label="操作"  width="130">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete "  size="mini" style="margin-right:5px"  @click="deleteOrder(scope.row)"></el-button>
       </template>

      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="this.orderInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="this.orderInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </el-card>

  <el-dialog
    title="物流信息"
    :visible.sync="dialogVisible"
    width="50%">
    <span>这是一段信息</span>
  </el-dialog>
</div>
</template>

<script>
export default {
  created () {
    this.getOrder()
  },
  data () {
    return {
      orderId:'',
      ordersList: [],
      orderInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      dialogVisible: false
    }
  },
  methods: {
    async getOrder () {
      const { data: res } = await this.$http.get('order/findAllOrder')
      console.log(res)
      this.total = res.meta.length
      this.ordersList = res.meta
    },
    handleSizeChange (val) {
      this.orderInfo.pagesize = val
      this.getOrder()
    },
    handleCurrentChange (val) {
      this.orderInfo.pagenum = val
      this.getOrder()
    },
    location () {
      this.dialogVisible = true
    },
    async searchOrder(id) {
      const { data: res } = await this.$http.get(`order/findOrderById/${id}`)
      console.log(res)
      this.$message.success("查找成功")
      this.ordersList = [res.meta]
    },
    async deleteOrder(order) {
      const { data: res } = await this.$http.get(`order/deleteById?id=${order.orderId}`)
      console.log(res)
      this.$message.success("删除成功")
      this.getOrder()
    }
  },
  mounted() {
    this.getOrder()
  }
}
</script>

<style scoped>
.table  {
  margin-top:15px;
}
</style>
